﻿using System;
using System.Reflection;
using MaLu.Config;

namespace MaLu.Data
{
    public static class ProviderManager
    {
        private static IFactory factory = null;
        private static object lockObject = new object();

        static ProviderManager()
        {
        }

        private static void LoadFactory()
        {

            object obj = Activator.CreateInstance(Type.GetType(WebConfig.ProviderName)); if (obj == null)
                throw new ReflectionTypeLoadException(new Type[] { typeof(IFactory) }, null, "Load data factory error.");
            factory = obj as IFactory;
        }

        public static IFactory Factory
        {
            get
            {
                if (factory == null)
                {
                    lock (lockObject)
                    {
                        LoadFactory();
                    }
                }
                return factory;
            }
        }
    }
}
